package com.bee.user.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.bee.user.common.domain.RoleDO;
import com.bee.user.common.vo.RoleVO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * @author Damin.yang
 * @date 2019/08/18 17:19
 */
@Mapper
public interface RoleMapper extends BaseMapper<RoleDO> {

    String COLUMN = "id, name, enable, type, org_id, create_time, creator, update_time, updator, delete_time";

    /**
     * 查询用户拥有的角色
     * @param userId
     * @return
     */
    @Select("select ur.role_id from user_role ur inner join role r on ur.role_id = r.id " +
            "where ur.user_id = #{userId} and r.enable = 1")
    List<String> queryUserRole(@Param("userId") Long userId);

    /**
     * 查询所有
     * @return
     */
    @Select({"<script>",
            "select " + COLUMN + " from role ",
            "where 1 = 1",
            "<if test='name != null'> and name like CONCAT('%', #{name}, '%') </if>",
            "<if test='enable != null'> and enable = #{enable} </if>",
            "</script>"})
    List<RoleVO> queryAll(RoleVO roleVO);
}
